package ema.jee.tp.client;

import javax.naming.InitialContext;
import javax.naming.NamingException;

public class EjbLocator {

	private static EjbLocator instance = new EjbLocator();

	public static EjbLocator getInstance() {
		return instance;
	}

	public <T> T getEjbLocal(String name) {
		try {
			T service = (T) new InitialContext().lookup("bankEAR/" + name
					+ "/local");
			return service;
		} catch (NamingException e) {
			e.printStackTrace();
			return null;
		}
	}
	public <T> T getEjbRemote(String name) {
		String jndiString = "bankEAR/" + name+ "/remote";
		System.out.println("looking for "+jndiString);
		try {
			T service = (T) new InitialContext().lookup(jndiString);
			return service;
		} catch (NamingException e) {
			e.printStackTrace();
			return null;
		}
	}

}